"""
@Project:p8项目
@File:user_model.py
@Author:柴奇峰
@Date:17:01
"""


from model import db
from model.courses import Comments

class User(db.Model):
    __tablename__ = 'user_tb'
    uid = db.Column(db.Integer, primary_key=True, autoincrement=True, doc='用户ID')
    mobile = db.Column(db.String(32), doc='手机号')
    password = db.Column(db.String(256), doc='密码')
    uname = db.Column(db.String(32), doc='昵称')
    account = db.Column(db.String(50),doc='头像')
    gender = db.Column(db.Integer, default=1, doc='1男0女')
    email = db.Column(db.String(64), nullable=True, doc='邮箱')
    comment = db.relationship('Comments',backref='comment_user')
    vip_expiration = db.Column(db.DateTime, nullable=True, doc='vip到期时间')
    # 会员
    vip = db.Column(db.Integer, db.ForeignKey('vip.id', ondelete="CASCADE"), doc="vip表")

    # comment = db.relationship('Comment',backref='tb_user')


class Vip(db.Model):
    """会员用户"""
    __tablename__ = 'vip'
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(32), doc='vip名称')
    level = db.Column(db.Integer, doc='vip等级(普通会员,高级会员)')
    price = db.Column(db.DECIMAL(20, 2), doc='会员价格')
    desc = db.Column(db.String(64), doc='vip描述')
    period = db.Column(db.Integer, default=365, doc='vip有效期')
    exempt_cour = db.Column(db.Integer, doc='免费课程{0或空:不享受,1:享受}')
    vip_cour = db.Column(db.Integer, doc='会员课程{0或空:不享受,1:享受}')
    environment = db.Column(db.Integer, doc='实验环境联网{0或空:不享受,1:享受}')
    save = db.Column(db.Integer, doc='保存2个环境(30天){0或空:不享受,1:享受}')
    client = db.Column(db.Integer, doc='客户端{0或空:不享受,1:享受}')
    ssh = db.Column(db.Integer, doc='SSH直连{0或空:不享受,1:享受}')
    web_ide = db.Column(db.Integer, doc='WebIDE {0或空:不享受,1:享受}')
    discounts = db.Column(db.Integer, doc='训练营优惠{0或空:不享受,1:享受}')
    exempt_study = db.Column(db.Integer, doc='训练营课程免费学习{0或空:不享受,1:享受}')
    user = db.Column(db.Integer,db.ForeignKey('user_tb.uid',ondelete="CASCADE"))

class OAuthUserModel(db.Model):
    '''
    三方登录的表，记录当前三方登录和用户的关系
    '''
    __tablename__ = 'oauth_user'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True ,doc='oauth_user id')
    image = db.Column(db.String(256), doc='头像')
    oauth_id = db.Column(db.String(512), doc='第三方登录的id')
    user = db.Column(db.Integer, db.ForeignKey("user_tb.uid", ondelete="CASCADE"))
    oauth_type = db.Column(db.String(128), doc='第三方登录类型')
